}
static void
-gtk_functions_list_item_factory_bind (GtkListItemFactory *factory,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected)
-{
- GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
-
- GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item, position, item, selected);
-
- if (self->bind_func)
- self->bind_func (list_item, self->user_data);
-}
-
-static void
-gtk_functions_list_item_factory_rebind (GtkListItemFactory *factory,
+gtk_functions_list_item_factory_update (GtkListItemFactory *factory,
GtkListItem *list_item,
guint position,
gpointer item,
{
GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
- GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item, position, item, selected);
+ GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->update (factory, list_item, position, item, selected);
- if (self->bind_func)
+ if (item != NULL && self->bind_func)
self->bind_func (list_item, self->user_data);
}
object_class->finalize = gtk_functions_list_item_factory_finalize;
factory_class->setup = gtk_functions_list_item_factory_setup;
- factory_class->bind = gtk_functions_list_item_factory_bind;
- factory_class->rebind = gtk_functions_list_item_factory_rebind;
+ factory_class->update = gtk_functions_list_item_factory_update;
}
static void
}
static void
-gtk_list_item_factory_default_bind (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected)
-{
- gtk_list_item_set_item (list_item, item);
- gtk_list_item_set_position (list_item, position);
- gtk_list_item_set_selected (list_item, selected);
-}
-
-static void
-gtk_list_item_factory_default_rebind (GtkListItemFactory *self,
+gtk_list_item_factory_default_update (GtkListItemFactory *self,
GtkListItem *list_item,
guint position,
gpointer item,
gtk_list_item_set_selected (list_item, selected);
}
-static void
-gtk_list_item_factory_default_update (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gboolean selected)
-{
- gtk_list_item_set_position (list_item, position);
- gtk_list_item_set_selected (list_item, selected);
-}
-
-static void
-gtk_list_item_factory_default_unbind (GtkListItemFactory *self,
- GtkListItem *list_item)
-{
- gtk_list_item_set_item (list_item, NULL);
- gtk_list_item_set_position (list_item, 0);
- gtk_list_item_set_selected (list_item, FALSE);
-}
-
static void
gtk_list_item_factory_class_init (GtkListItemFactoryClass *klass)
{
klass->setup = gtk_list_item_factory_default_setup;
klass->teardown = gtk_list_item_factory_default_teardown;
- klass->bind = gtk_list_item_factory_default_bind;
- klass->rebind = gtk_list_item_factory_default_rebind;
klass->update = gtk_list_item_factory_default_update;
- klass->unbind = gtk_list_item_factory_default_unbind;
}
static void
GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->teardown (self, list_item);
}
-void
-gtk_list_item_factory_bind (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected)
-{
- g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
- g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
- g_object_freeze_notify (G_OBJECT (list_item));
-
- GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->bind (self, list_item, position, item, selected);
-
- g_object_thaw_notify (G_OBJECT (list_item));
-}
-
-void
-gtk_list_item_factory_rebind (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected)
-{
- g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
- g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
- g_object_freeze_notify (G_OBJECT (list_item));
-
- GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->rebind (self, list_item, position, item, selected);
-
- g_object_thaw_notify (G_OBJECT (list_item));
-}
-
void
gtk_list_item_factory_update (GtkListItemFactory *self,
GtkListItem *list_item,
guint position,
+ gpointer item,
gboolean selected)
{
g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
g_object_freeze_notify (G_OBJECT (list_item));
- GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->update (self, list_item, position, selected);
+ GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->update (self, list_item, position, item, selected);
g_object_thaw_notify (G_OBJECT (list_item));
}
-void
-gtk_list_item_factory_unbind (GtkListItemFactory *self,
- GtkListItem *list_item)
-{
- g_return_if_fail (GTK_IS_LIST_ITEM_FACTORY (self));
- g_return_if_fail (GTK_IS_LIST_ITEM (list_item));
-
- g_object_freeze_notify (G_OBJECT (list_item));
-
- GTK_LIST_ITEM_FACTORY_GET_CLASS (self)->unbind (self, list_item);
-
- g_object_thaw_notify (G_OBJECT (list_item));
-}
void (* teardown) (GtkListItemFactory *self,
GtkListItem *list_item);
- /* bind @list_item to the given @item, which is in @position and @selected state */
- void (* bind) (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected);
- /* unbind the current item and bind a new one */
- void (* rebind) (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected);
- /* like GtkListItemFactoryClass::rebind(), but the item didn't change */
+ /* Update properties on @list_item to the given @item, which is in @position and @selected state.
+ * One or more of those properties might be unchanged. */
void (* update) (GtkListItemFactory *self,
GtkListItem *list_item,
guint position,
+ gpointer item,
gboolean selected);
- /* undo the effects of GtkListItemFactoryClass::bind() */
- void (* unbind) (GtkListItemFactory *self,
- GtkListItem *list_item);
};
void gtk_list_item_factory_setup (GtkListItemFactory *self,
void gtk_list_item_factory_teardown (GtkListItemFactory *self,
GtkListItem *list_item);
-void gtk_list_item_factory_bind (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected);
-void gtk_list_item_factory_rebind (GtkListItemFactory *self,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected);
void gtk_list_item_factory_update (GtkListItemFactory *self,
GtkListItem *list_item,
guint position,
+ gpointer item,
gboolean selected);
-void gtk_list_item_factory_unbind (GtkListItemFactory *self,
- GtkListItem *list_item);
G_END_DECLS
item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
selected = gtk_selection_model_is_selected (self->model, position);
- gtk_list_item_widget_bind (GTK_LIST_ITEM_WIDGET (result), position, item, selected);
+ gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (result), position, item, selected);
g_object_unref (item);
gtk_widget_insert_after (result, self->widget, prev_sibling);
item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
if (g_hash_table_steal_extended (change, item, NULL, (gpointer *) &result))
{
- gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (result), position, FALSE);
+ GtkListItemWidget *list_item = GTK_LIST_ITEM_WIDGET (result);
+ gtk_list_item_widget_update (list_item,
+ position,
+ gtk_list_item_widget_get_item (list_item),
+ gtk_list_item_widget_get_selected (list_item));
gtk_widget_insert_after (result, self->widget, prev_sibling);
/* XXX: Should we let the listview do this? */
gtk_widget_queue_resize (result);
item = g_list_model_get_item (G_LIST_MODEL (self->model), position);
selected = gtk_selection_model_is_selected (self->model, position);
- gtk_list_item_widget_rebind (GTK_LIST_ITEM_WIDGET (list_item), position, item, selected);
+ gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (list_item),
+ position,
+ item,
+ selected);
gtk_widget_insert_after (list_item, _gtk_widget_get_parent (list_item), prev_sibling);
g_object_unref (item);
}
GtkWidget *item,
guint position)
{
+ GtkListItemWidget *list_item = GTK_LIST_ITEM_WIDGET (item);
gboolean selected;
g_return_if_fail (GTK_IS_LIST_ITEM_MANAGER (self));
g_return_if_fail (GTK_IS_LIST_ITEM_WIDGET (item));
selected = gtk_selection_model_is_selected (self->model, position);
- gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (item), position, selected);
+ gtk_list_item_widget_update (list_item,
+ position,
+ gtk_list_item_widget_get_item (list_item),
+ selected);
}
/*
if (self->item)
{
- if (self->item->item)
- gtk_list_item_factory_unbind (self->factory, self->item);
gtk_list_item_factory_teardown (self->factory, self->item);
self->item->owner = NULL;
g_clear_object (&self->item);
return GTK_WIDGET (result);
}
-void
-gtk_list_item_widget_bind (GtkListItemWidget *self,
- guint position,
- gpointer item,
- gboolean selected)
-{
- if (self->factory)
- gtk_list_item_factory_bind (self->factory, self->item, position, item, selected);
-
- if (selected)
- gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
- else
- gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-}
-
-void
-gtk_list_item_widget_rebind (GtkListItemWidget *self,
- guint position,
- gpointer item,
- gboolean selected)
-{
- if (self->factory)
- gtk_list_item_factory_rebind (self->factory, self->item, position, item, selected);
-
- if (selected)
- gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
- else
- gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
- gtk_css_node_invalidate (gtk_widget_get_css_node (GTK_WIDGET (self)), GTK_CSS_CHANGE_ANIMATIONS);
-}
-
void
gtk_list_item_widget_update (GtkListItemWidget *self,
guint position,
+ gpointer item,
gboolean selected)
{
- if (self->factory)
- gtk_list_item_factory_update (self->factory, self->item, position, selected);
+ gtk_list_item_factory_update (self->factory, self->item, position, item, selected);
if (selected)
gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
else
gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
-}
-
-void
-gtk_list_item_widget_unbind (GtkListItemWidget *self)
-{
- if (self->factory)
- gtk_list_item_factory_unbind (self->factory, self->item);
-
- gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
- gtk_css_node_invalidate (gtk_widget_get_css_node (GTK_WIDGET (self)), GTK_CSS_CHANGE_ANIMATIONS);
}
void
return self->item->item;
}
+gboolean
+gtk_list_item_widget_get_selected (GtkListItemWidget *self)
+{
+ return self->item->selected;
+}
+
GtkWidget * gtk_list_item_widget_new (GtkListItemFactory *factory,
const char *css_name);
-void gtk_list_item_widget_bind (GtkListItemWidget *self,
- guint position,
- gpointer item,
- gboolean selected);
-void gtk_list_item_widget_rebind (GtkListItemWidget *self,
- guint position,
- gpointer item,
- gboolean selected);
void gtk_list_item_widget_update (GtkListItemWidget *self,
guint position,
+ gpointer item,
gboolean selected);
-void gtk_list_item_widget_unbind (GtkListItemWidget *self);
void gtk_list_item_widget_add_child (GtkListItemWidget *self,
GtkWidget *child);
guint gtk_list_item_widget_get_position (GtkListItemWidget *self);
gpointer gtk_list_item_widget_get_item (GtkListItemWidget *self);
+gboolean gtk_list_item_widget_get_selected (GtkListItemWidget *self);
G_END_DECLS
}
static void
-gtk_signal_list_item_factory_bind (GtkListItemFactory *factory,
- GtkListItem *list_item,
- guint position,
- gpointer item,
- gboolean selected)
-{
- GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->bind (factory, list_item, position, item, selected);
-
- g_signal_emit (factory, signals[BIND], 0, list_item);
-}
-
-static void
-gtk_signal_list_item_factory_rebind (GtkListItemFactory *factory,
+gtk_signal_list_item_factory_update (GtkListItemFactory *factory,
GtkListItem *list_item,
guint position,
gpointer item,
gboolean selected)
{
- g_signal_emit (factory, signals[UNBIND], 0, list_item);
+ if (gtk_list_item_get_item (list_item))
+ g_signal_emit (factory, signals[UNBIND], 0, list_item);
- GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->bind (factory, list_item, position, item, selected);
+ GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->update (factory, list_item, position, item, selected);
- g_signal_emit (factory, signals[BIND], 0, list_item);
-}
-
-static void
-gtk_signal_list_item_factory_unbind (GtkListItemFactory *factory,
- GtkListItem *list_item)
-{
- g_signal_emit (factory, signals[UNBIND], 0, list_item);
-
- GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->unbind (factory, list_item);
+ if (item)
+ g_signal_emit (factory, signals[BIND], 0, list_item);
}
static void
gtk_signal_list_item_factory_teardown (GtkListItemFactory *factory,
GtkListItem *list_item)
{
+ if (gtk_list_item_get_item (list_item))
+ g_signal_emit (factory, signals[UNBIND], 0, list_item);
+
g_signal_emit (factory, signals[TEARDOWN], 0, list_item);
GTK_LIST_ITEM_FACTORY_CLASS (gtk_signal_list_item_factory_parent_class)->teardown (factory, list_item);
GtkListItemFactoryClass *factory_class = GTK_LIST_ITEM_FACTORY_CLASS (klass);
factory_class->setup = gtk_signal_list_item_factory_setup;
- factory_class->bind = gtk_signal_list_item_factory_bind;
- factory_class->rebind = gtk_signal_list_item_factory_rebind;
- factory_class->unbind = gtk_signal_list_item_factory_unbind;
factory_class->teardown = gtk_signal_list_item_factory_teardown;
+ factory_class->update = gtk_signal_list_item_factory_update;
/**
* GtkSignalListItemFactory::setup: